Repository navigation
fix: define help_msg in main() so --help works from the textfsm script - #153
Merged
Merged
Conversation
help_msg was only set under `if __name__ == '__main__':`, but the installed `textfsm` console script calls textfsm.parser:main() directly, so `textfsm --help` failed with "NameError: name 'help_msg' is not defined". terminal.main() had the same problem when called directly. Build the usage line inside main() from argv[0], and add tests that call main() with --help.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
help_msgis only assigned underif __name__ == '__main__':. Thetextfsmconsole script installed by setup.py (textfsm=textfsm.parser:main) callsmain()directly, so that block never runs and--helpfails:python -m textfsm.parser --helpworks because it goes through the__main__block.textfsm.terminal.main()has the same pattern and fails the same way when it is called directly.This change builds the usage line inside
main()fromargv[0](which issys.argvunless the caller passes its own list) and drops the module-level assignment from the__main__blocks. The text of the usage line is unchanged.Tests: a
UnitTestMain.testHelpcase intests/textfsm_test.pyand intests/terminal_test.pycallsmain([..., '--help'])and checks the return value and the usage line. Both fail with theNameErrorabove without the change and pass with it.pytest tests: 110 passed. With the change, the installedtextfsm --helpprints the docstring and usage line and exits 0.This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.